package net.ddns.xcyyds.kungfu.procedures;

import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.event.TickEvent;

import net.minecraft.world.entity.Entity;

import net.ddns.xcyyds.kungfu.network.KungFuModVariables;

import javax.annotation.Nullable;

@Mod.EventBusSubscriber
public class JumpTwiceProcedure {
	@SubscribeEvent
	public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
		if (event.phase == TickEvent.Phase.END) {
			execute(event, event.player);
		}
	}

	public static void execute(Entity entity) {
		execute(null, entity);
	}

	private static void execute(@Nullable Event event, Entity entity) {
		if (entity == null)
			return;
		if (entity.isOnGround()) {
			if ((entity.getCapability(KungFuModVariables.PLAYER_VARIABLES_CAPABILITY, null)
					.orElse(new KungFuModVariables.PlayerVariables())).qingGong == 0) {
				entity.getPersistentData().putDouble("jumpCount", 0);
			}
		}
		if (entity.isOnGround()) {
			if ((entity.getCapability(KungFuModVariables.PLAYER_VARIABLES_CAPABILITY, null)
					.orElse(new KungFuModVariables.PlayerVariables())).qingGong == 1) {
				entity.getPersistentData().putDouble("jumpCount", 3.6);
			}
		}
		if (entity.isOnGround()) {
			if ((entity.getCapability(KungFuModVariables.PLAYER_VARIABLES_CAPABILITY, null)
					.orElse(new KungFuModVariables.PlayerVariables())).qingGong == 2) {
				entity.getPersistentData().putDouble("jumpCount", 12.4);
			}
		}
		if (entity.isOnGround()) {
			if ((entity.getCapability(KungFuModVariables.PLAYER_VARIABLES_CAPABILITY, null)
					.orElse(new KungFuModVariables.PlayerVariables())).qingGong == 3) {
				entity.getPersistentData().putDouble("jumpCount", 8.5);
			}
		}
	}
}
